﻿// JScript File

visLang = "1";
var key = "visLang";

key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs != null)
    visLang = qs[1];

if(visLang != "2")
    visLang = "1";


function IsNumeric(sText){
    var ValidChars = "0123456789. +";
    var IsNumber=true;
    var Char;
    for (i = 0; i < sText.length && IsNumber == true; i++){ 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1){
            IsNumber = false;
        }
    }
    return IsNumber;
}
function isValidEmail(strEmail){
    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
    if (strEmail.search(validRegExp) == -1){
        return false;
    }
    return true;
}

function isValidEmail(strEmail)
    {
	    validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
	    if (strEmail.search(validRegExp) == -1)
		    return false;
	    return true;
    }
    
function sharePage()
{
    if(visLang == "2")
    {
        lblHThankYou = "Thank you, This page has just been sent to your friend!"
        lblHErrName = "Please enter your name!"
        lblHErrEmail = "Please enter your email!"
        lblHErrEmailValid = "Invalid email. Please enter your email again!"
        lblHErrFriendName = "Please enter your friend's name!"
        lblHErrFriendEmail = "Please enter your friend's email!";
        lblHErrFriendEmailValid = "Invalid email. Please enter your friend's email again!";
    }
    else
    {
        lblHThankYou = "Email của bạn đã được gửi thành công!"
        lblHErrName = "Vui lòng điền tên của bạn!"
        lblHErrEmail = "Vui lòng điền email của bạn!"
        lblHErrEmailValid = "Địa chỉ email không hợp lệ. Vui lòng nhập lại!"
        lblHErrFriendName = "Vui lòng điền tên người nhận!"
        lblHErrFriendEmail = "Vui lòng điền email người nhận!";
        lblHErrFriendEmailValid = "Địa chỉ email người nhận không hợp lệ. Vui lòng nhập lại!";
    }
    
    if($("#txtName").val() == "")
    {
        alert(lblHErrName);
        $("#txtName").focus();
        return false;
    }
    
    if($("#txtEmail").val() == "")
    {
        alert(lblHErrEmail);
        $("#txtEmail").focus();
        return false;
    }
    
    if(isValidEmail($("#txtEmail").val()) == false)
    {
        alert(lblHErrEmailValid);
        $("#txtEmail").focus();
        return false;
    }

    if($("#txtFriendName").val() == "")
    {
        alert(lblHErrFriendName);
        $("#txtFriendName").focus();
        return false;
    }
    
    if($("#txtFriendEmail").val() == "")
    {
        alert(lblHErrFriendEmail);
        $("#txtFriendEmail").focus();
        return false;
    }
    
    if(isValidEmail($("#txtFriendEmail").val()) == false)
    {
        alert(lblHErrEmailValid);
        $("#txtFriendEmail").focus();
        return false;
    }
    
    var dataString = "Name=" + $("#txtName").val() + "&&Email=" + $("#txtEmail").val() + "&&FriendName=" + $("#txtFriendName").val() + "&&FriendEmail=" + $("#txtFriendEmail").val() + "&&visLang=" + visLang + "&&Url=" + encodeURIComponent(window.location.href);
    jQuery.ajax({           
        type: "POST",
		url: "/msSharePageProcess.aspx",
		data: dataString,
		dataType: "html",
		success: function(html)
		{
		    $.prompt.close();
		    alert(lblHThankYou);
		}
    });
    
    return false;
}

function sharePaymentPage()
{
    if(visLang == "2")
    {
        lblHThankYou = "Thank you, This page has just been sent to your friend!"
        lblHErrName = "Please enter your name!"
        lblHErrEmail = "Please enter your email!"
        lblHErrEmailValid = "Invalid email. Please enter your email again!"
        lblHErrFriendName = "Please enter your friend's name "
        lblHErrFriendEmail = "Please enter your friend's email ";
        lblHErrFriendEmailValid = "Invalid email. Please enter your friend's email again!";
    }
    else
    {
        lblHThankYou = "Email của bạn đã được gửi thành công!"
        lblHErrName = "Vui lòng điền tên của bạn!"
        lblHErrEmail = "Vui lòng điền email của bạn!"
        lblHErrEmailValid = "Địa chỉ email không hợp lệ. Vui lòng nhập lại!"
        lblHErrFriendName = "Vui lòng điền tên người nhận "
        lblHErrFriendEmail = "Vui lòng điền email người nhận ";
        lblHErrFriendEmailValid = "Địa chỉ email người nhận không hợp lệ. Vui lòng nhập lại!";
    }
    
    if($("#txtPaymentName").val() == "")
    {
        alert(lblHErrName);
        $("#txtPaymentName").focus();
        return false;
    }
	else if($("#txtPaymentEmail").val() == "")
    {
        alert(lblHErrEmail);
        $("#txtPaymentEmail").focus();
        return false;
    }
    else if(isValidEmail($("#txtPaymentEmail").val()) == false)
    {
        alert(lblHErrEmailValid);
        $("#txtPaymentEmail").focus();
        return false;
    }
	else if($("#txtFriendName1").val() == "")
    {
        alert(lblHErrFriendName + "1!");
        $("#txtFriendName1").focus();
        return false;
    }
    else if($("#txtFriendEmail1").val() == "")
    {
        alert(lblHErrFriendEmail + "1!");
        $("#txtFriendEmail1").focus();
        return false;
    }
    else if(isValidEmail($("#txtFriendEmail1").val()) == false)
    {
        alert(lblHErrEmailValid);
        $("#txtFriendEmail1").focus();
        return false;
    }
	else if($("#txtFriendName2").val() != "" && $("#txtFriendEmail2").val() == "")
    {
        alert(lblHErrFriendEmail + "1!");
        $("#txtFriendEmail2").focus();
        return false;
    }
	else if($("#txtFriendEmail2").val() != "" && $("#txtFriendName2").val() == "")
    {
        alert(lblHErrFriendName + "1!");
        $("#txtFriendName2").focus();
        return false;
    }
    else if($("#txtFriendName2").val() !="" && isValidEmail($("#txtFriendEmail2").val()) == false)
    {
        alert(lblHErrEmailValid);
        $("#txtFriendEmail2").focus();
        return false;
    }
	else if($("#txtFriendName3").val() != "" && $("#txtFriendEmail3").val() == "")
    {
        alert(lblHErrFriendEmail);
        $("#txtFriendEmail3").focus();
        return false;
    }
	else if($("#txtFriendEmail3").val() != "" && $("#txtFriendName3").val() == "")
    {
        alert(lblHErrFriendName);
        $("#txtFriendName3").focus();
        return false;
    }
    else if($("#txtFriendName3").val() !="" && isValidEmail($("#txtFriendEmail3").val()) == false)
    {
        alert(lblHErrEmailValid);
        $("#txtFriendEmail3").focus();
        return false;
    }
	
	$("#jqi_state0_buttonOK").hide();
	
    var dataString = "Name=" + $("#txtPaymentName").val() + "&&Email=" + $("#txtPaymentEmail").val() 
	dataString += "&&FriendName1=" + $("#txtFriendName1").val() + "&&FriendEmail1=" + $("#txtFriendEmail1").val() 
	dataString += "&&FriendName2=" + $("#txtFriendName2").val() + "&&FriendEmail2=" + $("#txtFriendEmail2").val() 
	dataString += "&&FriendName3=" + $("#txtFriendName3").val() + "&&FriendEmail3=" + $("#txtFriendEmail3").val() 
	dataString += "&&visLang=" + visLang + "&&txtMovieName=" + $("#txtMovieName").val() + "&&txtCinemaName=" + $("#txtCinemaName").val() + "&&txtTicketInfo=" + $("#txtTicketInfo").val() + "&&txtBookingNo=" + $("#txtBookingNo").val() + "&&txtOrderTotal=" + $("#txtOrderTotal").val() + "&&txtSessionDate=" + $("#txtSessionDate").val() + "&&txtSessionTime=" + $("#txtSessionTime").val() + "&&Url=" + encodeURIComponent(window.location.href);
    jQuery.ajax({           
        type: "POST",
		url: "/msSharePaymentProcess.aspx",
		data: dataString,
		dataType: "html",
		success: function(html)
		{
		    $.prompt.close();
		    alert(lblHThankYou);
		}
    });
    
    return false;
}




function addFeedback()
{    
    if(visLang == "2")
    {
        lblHErrOnOverall = "Please give your feedback on Overall!";
        lblHErrOnDesign = "Please give your feedback on Design!";
        lblHErrOnContent = "Please give your feedback on Content!";
        lblHErrOnEaseOfUse = "Please give your feedback on Ease of Use!";
        lblHErrOnHowOften = "How often do you vist MegaStar website?";
        lblHErrOnEmail = "Please enter your valid email Address!";
        lblHThankYou = "Thank you. Your feedback is greatly appreciated."
    }
    else
    {
        lblHErrOnOverall = "Vui lòng cho ý kiến về toàn diện trang web!";
        lblHErrOnDesign = "Vui lòng cho ý kiến về thiết kế của trang web!";
        lblHErrOnContent = "Vui lòng cho ý kiến về Nội dung của trang web!";
        lblHErrOnEaseOfUse = "Vui lòng cho ý kiến về Tính năng của trang web!";
        lblHErrOnHowOften = "Bạn có thường xuyên vào trang web MegaStar?";
        lblHErrOnEmail = "Vui lòng nhập địa chỉ email hợp lệ!";
        lblHThankYou = "Chân thành cám ơn ý kiến phản hồi quý báu của bạn."
    }
    
    var overall = "";
    try
    {
        overall = $("input[name='rad_overall']:checked").val();
        overall = overall.replace("rad_overall","");
    }
    catch(err)
    {
        alert(lblHErrOnOverall);
        return false;
    }
    
    var design = "";
    try
    {
        design = $("input[name='rad_design']:checked").val();
        design = design.replace("rad_design","");
    }
    catch(err)
    {
        alert(lblHErrOnDesign);
        return false;
    }
    
    var content = "";
    try
    {
        content = $("input[name='rad_content']:checked").val();
        content = content.replace("rad_content","");
    }
    catch(err)
    {
        alert(lblHErrOnContent);
        return false;
    }
    
    var ease = "";
    try
    {
        ease = $("input[name='rad_ease']:checked").val();
        ease = ease.replace("rad_ease","");
    }
    catch(err)
    {
        alert(lblHErrOnEaseOfUse);
        return false;
    }
    
    var how_often = "";
    //alert("rad_how_often: " + $("input[name='rad_how_often']:checked").val());
    try
    {
        how_often = $("input[name='rad_how_often']:checked").val();
        how_often = how_often.replace("rad_how_often","");
    }
    catch(err)
    {
        alert(lblHErrOnHowOften);
        return false;
    }
    
    var email = "";
    if($("#txt_email").val() != "")
    {
        if(isValidEmail($("#txt_email").val()) == false)
        {
            alert(lblHErrOnEmail);
            return false;
        }
        else
        {
            email = $("#txt_email").val();
        }
    }
    
    var date = $("#date").val();
    var month = $("#month").val();
    var year = $("#year").val();
    
    var dob = date + '-' + month + '-' + year;
    
    var province = $("#ddl_province").val();
    
    var suggess = $("#txt_suggess").val();
    while(suggess.indexOf("\n")!=-1){
        suggess = suggess.replace("\n","~13~");
    }
    
    //var suggess = $("#txt_suggess").val();
    
    var gender = "0";
    try
    {
        gender = $("input[name='rad_gender']:checked").val();
        gender = gender.replace("rad_gender","");
    }
    catch(err)
    {
    }
	
	$("#jqi_state0_buttonOK").hide();
	
    var dataString = "overall=" + overall + "&&design=" + design + "&&content=" + content + "&&ease=" + ease + "&&how_often=" + how_often + "&&email=" + email + "&&dob=" + dob + "&&province=" + province + "&&suggess=" + suggess + "&&gender=" + gender + "&&visLang=" + visLang;
    jQuery.ajax({           
        type: "POST",
		url: "/msFeedbackProcess.aspx",
		data: dataString,
		dataType: "html",
		success: function(html)
		{
		    $.prompt.close();
		    alert(lblHThankYou);
		}
    });
    
    
    
    return false;
}

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag){  
	 var i;
	var returnString = "";
	for (i = 0; i < s.length; i++)
	{   
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function daysInFebruary (year){
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var dtCh= "/";
	var minYear=1900;
	var maxYear=2100;
	
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
	return true
}

function checkInternationalPhone(strPhone)
{
    var validWorldPhoneChars = "";
    var minDigitsInIPhoneNumber = 10;
	//s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(strPhone) && strPhone.length >= minDigitsInIPhoneNumber);
}

function is_cell_phone(str){
	var digits = "0123456789";
    var phoneNumberDelimiters = "()- ";
    var validWorldPhoneChars = phoneNumberDelimiters + "+";
    var minDigitsInIPhoneNumber = 10;

	
	if(str.substring(0,2) == "09" || str.substring(0,2) == "01"){
		if(str.substring(0,2) == "09" && str.length != 10)
		{
			return false;
		}
		if(str.substring(0,2) == "01" && str.length != 11)
		{
			return false;
		}
		if (checkInternationalPhone(str)==false)
		{
			return false;
		}
		
		return true;
	}
	else
	{
		return false;
	}
}